package com.projectx.action.contact;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.projectx.R;

import java.util.ArrayList;
import java.util.List;

public class TabFragment extends Fragment {
    public static List<String> data_person=new ArrayList<>();
    public static List<String> data_group=new ArrayList<>();
    public static List<Bitmap>bitmaps=new ArrayList<>();
    private Context context;
    private String content; //Fragment的显示内容
    private RecyclerView recyclerView;
    public TabFragment(Context context,String content){
        this.context = context;
        this.content = content;
    }
    static {
        for (int i=1;i<=7;i++){
            data_person.add("好友"+i+"号");
            data_group.add("群聊"+i+"号");
            bitmaps.add(null);
        }
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    public void onResume(){
        recyclerView.getAdapter().notifyDataSetChanged();
        super.onResume();
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if (content.equals("好友")) {
            View view = inflater.inflate(R.layout.activity_friend, container, false);
            recyclerView =view.findViewById(R.id.recycler_view);
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
            recyclerView.setAdapter(new RVAdapter(context, data_person,bitmaps,false));
            recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
           /* for (int i=0;i<data_person.size();i++)
                Log.d("lzw",data_person.get(i));
            for (int i=0;i<data_group.size();i++)
                Log.d("lzw",data_person.get(i));*/
            return view;
        }
        else{
            View view = inflater.inflate(R.layout.activity_group, container, false);
            recyclerView =view.findViewById(R.id.recycler_view);
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
            recyclerView.setAdapter(new RVAdapter(context, data_group,bitmaps,true));
            recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
            return view;}
    }
   /* public void changedata(){
     try {
         recyclerView.getAdapter().notifyDataSetChanged();
     }catch (NullPointerException e){
         Log.d("lzw","RecycleView有毒");
     }
    }*/
}